TOP

VBA Function: LTrim

Description

The VBA LTRIM Function returns a string after removing spaces from the left of the string.


LTRIM Syntax

LTrim(text)

VBA LTrim Example

Trim spaces from the left side of a string only:

Sub LTrimExample()

     MsgBox LTrim("   test")           'Returns: "test"
     MsgBox LTrim("test   ")           'Returns: "test   "
     MsgBox LTrim("   test   ")        'Returns: "test   "
     MsgBox LTrim("   test   test   ") 'Returns: "test   test   "
    
End Sub
To remove spaces from the right side of the string only, use the RTRIM function.
To remove extraneous spaces from the beginning and end of the string, use the TRIM function.